<template>
  <view class="container">
    <!-- 顶部导航栏 -->
    <view class="nav-bar">
      <view class="back-btn" @click="navigateBack">
        <text>&lsaquo;&lsaquo;</text>
      </view>
      <view class="nav-title">优惠团购</view>
      <view class="nav-right"></view>
    </view>

    <!-- 团购列表 -->
    <view class="group-buy-list">
      <view 
        class="group-buy-item" 
        v-for="(item, index) in groupBuyItems" 
        :key="index"
        @click="navigateToDetail(item)"
      >
        <image 
          class="group-buy-image" 
          :src="item.imageUrl" 
          mode="aspectFill"
        ></image>
        <text class="group-buy-title">{{ item.title }}</text>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue';

// 团购数据
const groupBuyItems = ref([
  {
    id: '1',
    title: '北京四日追花拍摄秘密-故宫',
    imageUrl: 'https://img95.699pic.com/xsj/18/vt/8o.jpg!/fh/300',
    price: 99.00,
    originalPrice: 199.00,
    organizer: '济源广播旅游团',
    publishTime: '2022/10/10 11:09',
    deadline: '2022-10-20 23:59',
    contactPhone: '0391-66666666',
    description: '为了丰富小区业主周末生活，提高业主幸福感，焦作公交集团推出《公交社区带您游焦作》的周边游活动。《梦桃源温泉专线》根据报名人数派发车辆(最少30人起发);本周日上午9点发车。约半小时车程到达梦桃源水城温泉。'
  },
  {
    id: '2',
    title: '北京四日追花拍摄秘密-故宫',
    imageUrl: 'https://img95.699pic.com/xsj/18/vt/8o.jpg!/fh/300',
    price: 99.00,
    originalPrice: 199.00,
    organizer: '济源广播旅游团',
    publishTime: '2022/10/10 11:09',
    deadline: '2022-10-20 23:59',
    contactPhone: '0391-66666666',
    description: '为了丰富小区业主周末生活，提高业主幸福感，焦作公交集团推出《公交社区带您游焦作》的周边游活动。《梦桃源温泉专线》根据报名人数派发车辆(最少30人起发);本周日上午9点发车。约半小时车程到达梦桃源水城温泉。'
  },
  {
    id: '3',
    title: '北京四日追花拍摄秘密-故宫',
    imageUrl: 'https://img95.699pic.com/xsj/18/vt/8o.jpg!/fh/300',
    price: 99.00,
    originalPrice: 199.00,
    organizer: '济源广播旅游团',
    publishTime: '2022/10/10 11:09',
    deadline: '2022-10-20 23:59',
    contactPhone: '0391-66666666',
    description: '为了丰富小区业主周末生活，提高业主幸福感，焦作公交集团推出《公交社区带您游焦作》的周边游活动。《梦桃源温泉专线》根据报名人数派发车辆(最少30人起发);本周日上午9点发车。约半小时车程到达梦桃源水城温泉。'
  }
]);

// 返回上一页
const navigateBack = () => {
  uni.navigateBack();
};

// 跳转到详情页面
const navigateToDetail = (item) => {
  uni.navigateTo({
    url: `/pages/groupBuy/groupBuyDetail?id=${item.id}`
  });
};

onMounted(() => {
  console.log('团购列表页面加载完成');
});
</script>

<style scoped>
.container {
  background-color: #f8f8f8;
  min-height: 100vh;
}

/* 顶部导航栏 */
.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px;
  background-color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.back-btn {
  width: 40px;
  font-size: 20px;
  color: #333;
}

.nav-title {
  font-size: 18px;
  font-weight: bold;
  color: #333;
}

.nav-right {
  width: 40px;
}

/* 团购列表样式 */
.group-buy-list {
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.group-buy-item {
  background-color: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.group-buy-image {
  width: 100%;
  height: 150px;
}

.group-buy-title {
  padding: 10px;
  font-size: 14px;
  color: #333;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 响应式设计 */
@media (max-width: 375px) {
  .group-buy-list {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .group-buy-image {
    height: 120px;
  }
}

@media (min-width: 414px) {
  .group-buy-list {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .group-buy-image {
    height: 160px;
  }
}
</style>